package org.raymond.iworks.study.redis.lettuce;

/*
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
 */
import lombok.extern.slf4j.Slf4j;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class RedisLettuceTest {
    public static void main(String[] args) {
        String host = "192.168.0.125";
        String password = "";
        //standaloneTest(host, password);
    }

    /*
    private static void standaloneTest(String host, String password){
        // Syntax: redis://[password@]host[:port][/databaseNumber]
        // Syntax: redis://[username:password@]host[:port][/databaseNumber]
        // Standalone
        RedisURI redisUri = RedisURI.builder()
                .withSsl(false)
                .withHost(host)
                .withPort(6379)
                .build();
        RedisClient redisClient = RedisClient.create(redisUri);
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        System.out.println("Connected to Redis");

        // 同步
        RedisCommands<String, String> commands = connection.sync();
        commands.set("hello1", "123");


        connection.close();
        redisClient.shutdown();
    }

    private static void clusterTest(String host){
        // Syntax: redis://[password@]host[:port]
        // Syntax: redis://[username:password@]host[:port]
        String url = String.format("redis://%s:6379", host);
        RedisClusterClient redisClient = RedisClusterClient.create(url);
        StatefulRedisClusterConnection<String, String> connection = redisClient.connect();
        System.out.println("Connected to Redis using Redis Cluster");
        connection.close();
        redisClient.shutdown();
        // Cannot retrieve cluster partitions from
        // ERR This instance has cluster support disabled
    }

    public static void RedisSentinel(String host, String masterId){
        // Syntax: redis-sentinel://[password@]host[:port][,host2[:port2]][/databaseNumber]#sentinelMasterId
        String url = String.format("redis-sentinel://%1$s:26379,%1$s:26380/0#mymaster", host, masterId);
        RedisClient redisClient = RedisClient.create(url);
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        System.out.println("Connected to Redis using Redis Sentinel");
        connection.close();
        redisClient.shutdown();
    }
     */
}
